package com.qishon.pc.domain.service;

import com.aliyun.openservices.oss.OSSClient;
import com.qishon.pc.domain.util.GirardEnum;
import com.qishon.pc.domain.util.OSSApplication;
import lombok.extern.slf4j.Slf4j;
import org.springframework.amqp.rabbit.annotation.RabbitHandler;
import org.springframework.amqp.rabbit.annotation.RabbitListener;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.stereotype.Component;

import java.io.File;

/**
 * Created by yongwei.chen on 2017/1/3.
 */
@Component
@Slf4j
@RabbitListener(queues = "uploadReceiver")
public class UploadReceiverService {
    @Value("${OSS.ACCESS_ID}")
    private String ACCESS_ID;
    @Value("${OSS.OSS_ENDPOINT}")
    private String OSS_ENDPOINT;
    @Value("${OSS.ACCESS_KEY}")
    private String ACCESS_KEY;
    @Value("${OSS.BUCKET_NAME}")
    private String BUCKET_NAME;

    @Value("${run.path}")
    private String runPath;
    @RabbitHandler
    public void process(String msg){
        log.info("uploadReceiver:" + msg);
        String[] strArr = msg.split(",");
        String modelName = strArr[2];
//        String uploadRoot =runPath+"\\"+ "05.Upload"+"\\"+modelName;
        String uploadRoot = runPath+"\\"+ GirardEnum.findByKey(Integer.parseInt(strArr[0])-1).getFilePtah()+"\\"+modelName;
        log.info(uploadRoot);
        OSSClient client = new OSSClient(OSS_ENDPOINT, ACCESS_ID, ACCESS_KEY);
        File Root = new File(uploadRoot);
        log.info("enter showDir");
        OSSApplication.showDir(client,Root,BUCKET_NAME,modelName);
    }
}
